<template>
	<view class="page">
		<image src="/static/accreditBg.png" class="accreditBg" />
		<!-- 获取手机号 start -->
		<view class="content plr80 pt150">
			<view class="flex_aj pb80">
				<view class="h200 border-r50p">
					<!-- 云禾换电 -->
					<image :src="company_logo | formatImg('/static/logo3.jpeg')" @error="imgErr" mode="widthFix"
						style="width: 200upx; height: 200upx;"></image>
					<!-- 太航充电柜 -->
					<!-- <image :src="company_logo | formatImg('/static/logotaihang.png')" @error="imgErr" mode="widthFix"
						style="width: 200upx; height: 200upx;"></image> -->
					<!-- 顺鼎物联 -->
					<!-- <image :src="company_logo | formatImg('/static/logoshunding.png')" @error="imgErr" mode="widthFix"
						style="width: 200upx; height: 200upx;"></image> -->
					<!-- 中电充换 -->
					<!-- <image :src="company_logo | formatImg('/static/logozdch.jpg')" @error="imgErr" mode="widthFix"
						style="width: 200upx; height: 200upx;"></image> -->
				</view>
			</view>
			<!-- #ifdef MP-WEIXIN -->
			<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber"
				class="pw100 mt30 lh90 tac ft32 b-primary border-r6 cf fw btn_tap">手机号一键登录</button>
			<!-- #endif -->
			<!-- #ifdef MP-ALIPAY -->
			<button open-type="getAuthorize" @getAuthorize="getAliPhoneNumber" @error="onAuthError" scope="phoneNumber"
				class="pw100 mt30 lh90 tac ft32 b-primary border-r6 cf fw btn_tap">
				支付宝一键登录
			</button>
			<!-- #endif -->
		</view>
		<!-- 获取手机号  end -->


	</view>
</template>

<script>
	import {
		mapState,
		mapActions
	} from 'vuex'
	import {
		decodePhone,
		getGiveInfo,
		getPlatformInfo
	} from '@/api/public.js'
	import {
		Validator
	} from '@/utils/validate'
	export default {
		name: 'index',
		data() {
			return {
				pageType: 1, // 登录页 2
				dataForm: {
					mobile: '',
					code: null
				},
				company_logo: '',

				redBag: 0 // 红包金额
			}
		},
		onLoad(e) {
			this.getPlatformInfo()
		},
		computed: {
			...mapState({
				token: state => state.user.token,
				userInfo: state => state.user.userInfo
			})
		},
		onShow() {},
		methods: {
			...mapActions(['getUserInfo']),
			imgErr(e) {
				console.log(e)
			},
			onAuthError(e) {
				console.log('获取手机号')
				console.log(e)
			},
			async getPlatformInfo() {
				const res = await getPlatformInfo()
				if (res.data) {
					this.company_logo = res.data.logoUrl || ""
				}

			},
			// 获取手机号 -- 后台 (微信)
			async getPhoneNumber(e) {
				console.log('3434', e);
				if (e.detail.errMsg !== 'getPhoneNumber:ok') {
					return false
				}
				const {
					iv,
					encryptedData
				} = e.detail
				const wxAppId = uni.getAccountInfoSync().miniProgram.appId
				const res = await decodePhone({
					wxAppId,
					iv,
					encryptedData
				})
				console.log(res)
				await this.getUserInfo()
				this.toast(res.msg)
				if (res.code == 200) {
					// this.getGiveInfo()
					this.goWallet()
				}
			},


			// 跳转 我的钱包 
			goWallet() {
				uni.redirectTo({
					url: '/pages/user/wallet/index'
				})
			},

			// 获取支付宝手机号
			getAliPhoneNumber(e) {
				console.log('获取支付宝手机号')
				console.log(e)
				const _self = this
				my.getPhoneNumber({
					success: res => {
						console.log(res)
						let encryptedData = JSON.parse(res.response).response
						console.log(encryptedData)
					},
					fail: res => {
						console.log(res)
						console.log('getPhoneNumber_fail')
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.close_btn {
		width: 56upx;
		height: 56upx;
		background-color: #FF3536;
	}

	.cp_w {
		position: relative;
		width: 654upx;
		height: 876upx;

		.cp_img {
			position: absolute;
			left: 0;
			top: 0;
			z-index: 0;
		}

		.cp_c {
			position: relative;
			z-index: 1;
			padding-top: 370upx;

			.cp_money {

				font-family: Source Han Sans CN;
				font-weight: bold;
				color: #ffffff;
				// line-height: 206px;
				// text-shadow: 0px 4px 0px rgba(167, 7, 46, 0.45);
				background: linear-gradient(180deg, #fffdc9 0%, #ffdb6d 100%);
				-webkit-background-clip: text;
				-webkit-text-fill-color: transparent;
			}
		}
	}

	.page {
		width: 100vw;
		height: 100vh;

		.accreditBg,
		.content {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
		}

		.reject {
			background: #ccc;
		}
	}

	.pt100 {
		padding-top: 100px;
	}

	.w400 {
		width: 400upx;
	}

	.lineY {
		width: 1px;
		height: 40upx;
		background: #ccc;
	}

	.register {
		border: 1px solid $primary;
		border-radius: 10upx;
		color: $primary;
	}
</style>